<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
Object obj=request.getSession().getAttribute("role_resource");
if(null==obj){
	response.setStatus(1000);
	return;
}
%> 
<html>	
<style type="text/css">
			.ext-el-mask{
				  background-color: #FFFFFF;
			}
		</style>
		<script type="text/javascript">
	function show_img(path) {
		var win=Ext.getCmp("showimages");
		win.show();
		var html="<img id='imgpage' width="+win.getInnerWidth()+" height="+win.getInnerHeight()+" src='download.action?id="+encodeURI(path)+"' />";
		win.update(html);
    };	
	Ext.onReady(function() {

	var img_index = 0;//图片路径下表
	var prod_opera;//传给ajax url属性的action字符串
	var opt=false;//增加规则按钮操作标示

	//状态下拉列表
	var state_store =  new Ext.data.JsonStore({
			fields: ["id", "text"],
			data: [{id:"0",text:"退回"},{id:"1",text:"启用"},{id:"2",text:"草稿"},{id:"3",text:"审核中"}]
		});
	//规则类型下拉列表
	var type_store= new Ext.data.JsonStore( {
		fields : ["id", "text"],
		data:[{id:"1",text:"自定义"},{id:"0",text:"默认"}]
	});

	//模板下拉列表
	var temp_sotre=new Ext.data.JsonStore( {
		root: "data",
		fields : ["id", "name"],
		url:"template!listAll.action"
	});
	//素材数据
var fodder_store=new Ext.data.JsonStore({
	    		root: "data",
	    		totalProperty: "total",
	    		baseParams:{"fodder.state":1},
	    		fields: ["id","name","type"],
	    		url: "fodder!listNo.action"
});

//获取符合规则的全部素材数据,因素材分页
function loadFodderByRule(type,pbegen,pend){
	fodder_store.baseParams["fodder.type"] = type;
	fodder_store.baseParams["fodder.begin"] = pbegen;
	fodder_store.baseParams["fodder.end"] = pend;
}
	
	//搜索条件模板下拉列表
	var temp_sotre1=new Ext.data.JsonStore( {
		root: "data",
		fields : ["id", "name"],
		url:"template!listAll.action",
		listeners : {
				"load": function() {
					var RecordName = Ext.data.Record.create([
						{name: "id"},
						{name: "name"}
					]);
					var newRecord = new RecordName({
					    id:"",
						name: "全部"
					});
					this.insert(0,newRecord);
				}
			}
	});
	//搜索条件规则类型下拉列表
	var type_store1= new Ext.data.JsonStore( {
		fields : ["id", "text"],
		data:[{id:"",text:"全部"},{id:"1",text:"自定义"},{id:"0",text:"默认"}]
	});
	//搜索条件模板类型下拉列表
	var type_store2= new Ext.data.JsonStore( {
		fields : ["id", "text"],
		data:[{id:"",text:"全部"},{id:"1",text:"纸质"},{id:"2",text:"电子"}]
	});
	
	//个性化区域
	var area_store=new Ext.data.JsonStore( {
		root : "data",
		totalProperty : "total",
		fields : ["id","name", "type","remark"],
		url:"templatearea!list.action"
	});
	
	//个性化区域规则数据源
	var store = new Ext.data.JsonStore( {
		root : "data",
		totalProperty : "total",
		fields : [ "rule_no", "rule_name", "rule_type","stencil_no","stencil_name","stencil_ver", "stenciltype_no",
				   "period_begen","period_end","rule_pri","person_no","create_time","remark","areaNo",
				   "areaName","rule_state","fodderType"],
		url: "rule!etGridList.action"
	});
	
	//个性化区域规则从表数据源
	var f_store = new Ext.data.JsonStore( {
		root : "data",
		totalProperty : "total",
		fields : [ "id", "ruleno", "fodder","pri"],
		url: "rule!listRuleParam.action"
	});
	
	var rule_record = Ext.data.Record.create([
		"id","ruleno","fodder","pri"
	]);
	//规则模拟数据
	var rule_store=  new Ext.data.JsonStore({
			root : "data",
			idProperty: "idx",
			fields:["id","idx","opr1","value1","opr2","value2","cif","type"],
			url : "rule!listRuleOper.action"
		});
	var ope_store= new Ext.data.JsonStore({
		fields : ["id", "text"],
		data:[{id:"0",text:"等于"},{id:"1",text:"大于"},{id:"2",text:"小于"},{id:"3",text:"大于等于"},{id:"4",text:"小于等于"}]
	});
	
	
	
	var lj_store= new Ext.data.JsonStore({
		fields : ["id", "text"],
		data:[{id:"0",text:"或者"},{id:"1",text:"并且"}]
	});
	
	var  ljRenderer=function(input){
 		if(""==input)return input;
		var res2=lj_store.getById(input);
		return res2.data.text;
	};
	
	var field_store=new Ext.data.JsonStore({
		root : "data",
		fields:["id","text"],
		url : "billFodder!listField.action"
	});
	var  oprRenderer=function(input){
		if(""==input)return input;
		var res2=ope_store.getById(input);
		return res2.data.text;
	};
	var fieldRenderer=function(input){
		if(""==input)return input;
		var res2=field_store.getById(input);
		return res2.data.text;
	};
	var opecombox={
		xtype:"billCombox",
		store:ope_store
	};
	var fieldcombox={
		xtype:"billCombox",
		store:field_store
	};
	//逻辑符下拉列表
	var ljcombox={
		xtype:"billCombox",
		valueField:"id",
		displayField: "text",
		store:lj_store
	};
		//图片路径,上传
	var image_store=new Ext.data.JsonStore({
		root : "data",
		fields : [ "path" ],
		url : "template!queryImage.action"
	});
	var image_record = Ext.data.Record.create([
		"path"
	]);
	
	//修改时用的变量
	var stenciltype;
	
	var sel = function(){
	var node = Ext.getCmp("prod_tree").getSelectionModel().getSelectedNode();
	if(node&&node.isLeaf()){
	
		store.baseParams = store.baseParams || {};

		store.baseParams["ruleMaster.rule_type"] = Ext.getCmp("a").getValue();
		store.baseParams["ruleMaster.remark"] = Ext.getCmp("b").getValue();
		store.baseParams["ruleMaster.stenciltype_no"] = Ext.getCmp("c").getValue();
						
		store.load({params:{start:0,limit:limit}});
		}
		else
		{
		//Ext.Msg.alert("提示","未选中任何行卡产品信息,无法执行此操作!");
		 Ext.Msg.show({
		   title:"警告",
		   msg: "未选中任何行卡产品信息,无法执行此操作!",
		   buttons: Ext.Msg.OK,
		   animEl: "elId",
		   icon:Ext.MessageBox.WARNING
		});
		}
	};
		
	var p1 = {
		id : "p1Grid",
		xtype : "grid",
		loadMask : true,
		autoExpandColumn: "rule_name",//自动填充
		autoExpandMin : 100,//自动填充最小宽度
		store : store,
		headersDisabled: true,
		sm : new Ext.grid.RowSelectionModel(),
		columns : [ new Ext.grid.RowNumberer( {header : "序号",width : 35}), 
		            {dataIndex : "rule_no",			header : "规则编号",	menuDisabled: true},
		            {dataIndex : "rule_name",		header : "规则名称",		id:"rule_name",	menuDisabled: true},
		            {dataIndex : "rule_type",		header : "规则类别",		menuDisabled: true,
		             renderer:function(input){
 						 if("0"==input)return "默认";
            			 else if("1"==input)return "自定义";
		             }
		            },
		            {dataIndex : "stencil_name",	header : "模版名称",		menuDisabled: true},
		            {dataIndex : "stencil_ver",		header : "模板版本号",	menuDisabled: true},
		            {dataIndex : "stenciltype_no",	header : "模版类型编号",	menuDisabled: true,
			          renderer:function(input){
            			 if("1"==input)return "纸质";
            			 else if("2"==input)return "电子";
            			 else if("3"==input)return "短信";
            		  }
		            },                  
		            {dataIndex : "period_begen",	header : "账期开始月",	menuDisabled: true},
		            {dataIndex : "period_end",		header : "账期截止月",	menuDisabled: true},
		            {dataIndex : "rule_pri",		header : "优先级",	menuDisabled: true},		            
		            {dataIndex : "rule_state",		header : "状态",		menuDisabled: true,
			          renderer:function(input){
			          	 if("0" == input) return "退回";
            			 else if("1"==input)return "启用";
            			 else if("2"==input)return "草稿";
			          	  else if("3"==input)return "审核中";
            		  }
		            },
		           {dataIndex : "remark",		header : "备注",		menuDisabled: true}
		],
		bbar: new Ext.ux.PagingToolbar( {
			pageSize : limit,
			store : store
		}),
		buttonAlign : "center",
		buttons : [
				{
					text : "查看详情",
					id:'edit_temp',
					handler : function() {
						prod_opera = "rule!upd.action";
						var record = Ext.getCmp("p1Grid").getSelectionModel().getSelected();
						if (record) {
							stenciltype=record.data.stenciltype_no;
							rule_store.removeAll();
							area_store.load({params:{"temparea.tempno":record.data.stencil_no},callback:function (){
								Ext.getCmp("rule_panel").layout.setActiveItem(1);
								
								Ext.getCmp("areaform").setParam(record.data);
								//加载区域规则
								image_store.load({
								params : {"template.id" : record.data.stencil_no},
								callback:function(){
									var win=Ext.getCmp("imagePanel");
									win.show();
									img_index = 0;
									var page_num = "1/"+image_store.getCount();
                					Ext.getCmp("show_num").setText(page_num);
					
									var html="<a href=javascript:show_img('"+encodeURI(this.getAt(0).get('path'))+"');>"+
									"<img width="+win.getInnerWidth()+" height="+win.getInnerHeight()+" src='download.action?id="+encodeURI(this.getAt(0).get('path'))+"'/></a>";
									win.update(html);
								}
								});
								
								loadFodderByRule(area_store.getById(record.data.areaNo).data.type,record.data.period_begen,record.data.period_end);
							fodder_store.load({params:{},callback:function (){
								f_store.load( {
									params : {
										"ruleMaster.rule_no" : record.data.rule_no,
										"ruleMaster.areaNo" : record.data.areaNo
									}
								});
							}});
							}});				
						
						}
						else
						{ 
						   Ext.Msg.show({
		   						title:"警告",
		   						msg: "没有选中任何模板信息，无法进行此操作!",
		   						buttons: Ext.Msg.OK,
		   						animEl: "elId",
		   						icon:Ext.MessageBox.WARNING
								});
						   }
					}
				}],
			tbar:["&nbsp&nbsp规则类别:",
			 {
				id: "a",
				xtype: "billCombox",
				value: "",
				width: 120,
				store: type_store1,
				listeners: {
					"select": sel
				}
			},"&nbsp&nbsp模板类型:",
			{
				id: "c",
				xtype: "billCombox",
				value: "",
				width: 120,
				store: type_store2,
				listeners: {
					"select": sel
				}
			},"&nbsp&nbsp模板名称:",
			{
				id : "b",
					enableKeyEvents:true,
					xtype : "textfield",
					listeners : {
						'keypress' : function (  tobj ,   e  ){
							if(e.getKey()==e.ENTER)sel();
						} 
					}
			}]
	};

	var org_add_update = 0;

	var p2 = {
		id:"areaform",
		columnWidth: 1,
		height:302,
		xtype :"form",
		title:"个性化区域信息",
		bodyStyle : "padding:5px 5px 0",
		defaultType : "textfield",
		items : [
		{	itemId: "cardno",
			hidden: true,
			disabled:true,
			name : "cardno"},
		{	itemId: "rule_no",
			id:"ruleno",
			fieldLabel : "规则编号",
			hidden:true,
			disabled:true,
			anchor:"100%",
			name : "rule_no"},
		{	itemId: "rule_name",
			fieldLabel : "规则名称",
			anchor:"100%",
			disabled:true,
			allowBlank: false,
			vtype:"alphanumchinese",
					validator:function (val){
		        		if(val=="")return "该输入项为必输项!";
		        		if(Ext.fucCheckCHLength(val)>50){
		        			return "请输入50个字符范围内的值!<br>注：一个中文字符算两个字符的长度!";
		        		}
		        		return true;
		        	},
			name : "rule_name"},
		{	itemId: "rule_type",
			id:"ruleType",
			disabled:true,
			fieldLabel: "类别",
			allowBlank: false,
			name: "rule_type",
			xtype:"billCombox",
			store:type_store},
		{	itemId: "stencil_no",
			id:"stencilNo",
			fieldLabel:"模板名称",
			name :"stencil_no",
			disabled:true,
			allowBlank: false,
			xtype:"billCombox",
			store: temp_sotre,
			valueField: "id",
			displayField: "name",
			listeners: {
				"select": function() {
					area_store.load({params:{"temparea.tempno":this.value}});
					image_store.load({
					params : {"template.id" : this.value},
					callback:function(){
						var win=Ext.getCmp("imagePanel");
						win.show();
						var html="<a href=javascript:show_img('"+encodeURI(this.getAt(0).get('path'))+"');>"+
						"<img width="+win.getInnerWidth()+" height="+win.getInnerHeight()+" src='download.action?id="+encodeURI(this.getAt(0).get('path'))+"'/></a>";
						win.update(html);
					}
					});
					this.ownerCt.getComponent("areaNo").setValue("");
				}				
			} 
		},{
			itemId : "areaNo",
			fieldLabel : "区域名称",
			id:"area_no",
			name : "areaNo",
			allowBlank: false,
			disabled:true,
			xtype: "billCombox",
			store: area_store,
			valueField: "id",
			displayField: "name",
			listeners: {
				"select": function( combo , record ,  index ) {
					var type=area_store.getById(record.id).data.type;
					this.ownerCt.getComponent("fodderType").setValue(type);		
				}				
			}
		},
		{
			itemId : "fodderType",
			fieldLabel : "区域素材类型",
			id:"fodder_type",
			name : "fodderType",
			disabled:true,
			xtype: "billCombox",
			disabled:true,
			store: new Ext.data.JsonStore({
				fields : ["id", "name"],
				data:[{id:"1",name:"图片"},{id:"2",name:"文本"},{id:"3",name:"列表"},{id:"4",name:"自动填充"}]
			}),
			valueField: "id",
			displayField: "name"
		},{
			itemId : "period_begen",
			fieldLabel : "账期开始月",
			anchor:"100%",
			disabled:true,
			vtype: "daterange",
       		endDateField: "periodEnd",
			allowBlank: false,
			name : "period_begen",
			id:"periodBegen",
			xtype:"datefield",format:"Y-m",editable :false
		},{
			itemId : "period_end",
			fieldLabel : "账期截止月",
			anchor:"100%",
			id:"periodEnd",
			allowBlank: false,
			disabled:true,
			name : "period_end",
			vtype: "daterange",
       		startDateField: "periodBegen",
			xtype:"datefield",format:"Y-m",editable :false
		},{
			itemId : "rule_pri",
			fieldLabel : "优先级",
			anchor:"100%",
			name : "rule_pri",
			disabled:true,
			xtype:"numberfield",
			id:"rulePri",
			validator :function (val){
				if(val=="")return "该输入项为必输项!";
				if(val==0){
					return "优先级别不能为零!";	
				}
				return true;
			}
		},{
			itemId : "rule_state",
			fieldLabel : "状态",
			disabled:true,
			allowBlank: false,
			name : "rule_state",
			id:"ruleState",
			disabled:true,
			xtype:"billCombox",
			store:state_store
			
		},{
			itemId:"remark",
			fieldLabel:"备注",
			disabled:true,
			anchor:"100%",
			vtype:"alphanumchinese",
					validator:function (val){
		        		if(val=="")return true;
		        		if(Ext.fucCheckCHLength(val)>200){
		        			return "请输入200个字符范围内的值!<br>注：一个中文字符算两个字符的长度!";
		        		}
		        		return true;
		        	},
			name:"remark"
		}],
		buttonAlign : "center",
		setParam : function(data) {
			this.getComponent("rule_name").setValue(data.rule_name);
			this.getComponent("rule_type").setValue(data.rule_type);
			this.getComponent("stencil_no").setValue(data.stencil_no);
			this.getComponent("areaNo").setValue(data.areaNo);
			this.getComponent("period_begen").setValue(data.period_begen);
			this.getComponent("period_end").setValue(data.period_end);
			this.getComponent("rule_pri").setValue(data.rule_pri);
			this.getComponent("rule_state").setValue(data.rule_state);
			this.getComponent("areaNo").setValue(data.areaNo);
			this.getComponent("remark").setValue(data.remark);
			this.getComponent("fodderType").setValue(data.fodderType);
		}
	};
	var smpaper = new Ext.grid.CheckboxSelectionModel({
				singleSelect : true
			});// 添加复选框
	//预印纸数据源
	var paper_store = new Ext.data.JsonStore({
		root: "data",
	   	totalProperty: "total",
	   	fields : [ "pid","paper_no","paper_name","paper_weight",
	   	   	"person_no","create_time","period_begin","period_end","period_day","businpnt_name","businpnt_no"],
		url : "paper!paperByTimeCard.action"
	});
	
	var paper = {
		id : "paper",
		xtype : "grid",
		loadMask : true,
		store : paper_store,
		sm : smpaper,
		columns : [  new Ext.grid.RowNumberer({header: "序号", width: 35}),
					smpaper,
		            {dataIndex : "pid",			header : "序列号"},
		            {dataIndex : "paper_no",	header : "预印纸编号"},
		            {dataIndex : "businpnt_name",	header : "外包商"},
		            {dataIndex : "paper_name",	header : "名称"},      
		            {dataIndex : "paper_weight",header : "克重"},
		            {dataIndex : "period_begin",header : "有效开始月"},
		            {dataIndex : "period_end",	header : "有效截止月"},
		            {dataIndex : "period_day",	header : "账单日"},
		            {dataIndex : "person_no",	header : "创建人"},
		            {dataIndex : "create_time",	header : "创建时间"}
		],
		bbar: new Ext.ux.PagingToolbar( {
			pageSize : limit,
			store : paper_store
		})
	};

	var paperwin;
////////////////////////////////////////////////////////////////
	var win;
	//素材数据结果集
	var fdata=new Ext.data.JsonStore({
		    		root: "data",
		    		totalProperty: "total",
		    		baseParams:{"fodder.state":1},
		    		fields: ["id","name","type","docname","begin","end","state","url","remark","personno","createtime"],
		    		url: "fodder!list.action"
	});
	fdata.load({params:{start:0,limit:limit}});
	//素材状态下拉列表
    	var fodder_state_store= new Ext.data.JsonStore({
			fields: ["id", "text"],
			data: [{id:"0",text:"退回"},{id:"1",text:"启用"},{id:"2",text:"草稿"},{id:"3",text:"审核中"}]
		});
	var sm = new Ext.grid.CheckboxSelectionModel({
				singleSelect : true
			});// 添加复选框
	
	//选择素材
	var selectFodder = {
				id: "selectFodder",
				xtype: "grid",
				stripeRows: true,
				autoExpandColumn: "name",
				autoExpandMin: 100,
				store:fdata,
				sm : sm,
				columns:[
	    	    	new Ext.grid.RowNumberer(),
	    	    	sm,
    					{header: "编号",		dataIndex: "id"},
    					{header: "素材名称",	dataIndex: "name",	id: "name"},
    					{	header: "素材类型",	
    						dataIndex: "type",
    						renderer: function(data){
    							if("1" == data) return "图片";
    							else if("2" == data) return "文本";	
    							else if("3" == data) return "列表";	
    						}
    					},
    					{header: "文件名",	dataIndex: "docname"},
    					{header: "有效期起始月",	dataIndex: "begin"},
    					{header: "有效期截止月",	dataIndex: "end"},
    					{	header: "状态",	
    						dataIndex: "state",
    						renderer: function(input){
    							var res2=fodder_state_store.getById(input);
    							if(res2){
    								return (res2)?res2.data.text:"";
    							}
    							return "";
    						}
    					},
    					{header: "URL",	dataIndex: "url"},
    					{header: "备注",	dataIndex: "remark"},
    					{header: "操作人",	dataIndex: "personno"},
    					{header: "创建时间",	dataIndex: "createtime"}
				],
				bbar: new Ext.ux.PagingToolbar({
    	        	pageSize: limit,
    	        	store: fdata
    	    	})
			};
	
	var cm = new Ext.grid.ColumnModel({
        defaults: {
            sortable: true 
        },
        columns: [{
            id: "id",
            header: "序号",
            dataIndex: "id",
            width: 35
        },{
            id: "fodder",
            header: "素材名称",
            dataIndex: "fodder",
            width: 114,
            renderer:function (input){
        		if(""==input)return input;
				var res2=fodder_store.getById(input);
				if(res2){
					return res2.data.name;
				}
				return "";				
            },
            editor: new Ext.form.TextField({
                allowBlank: false
            })
           
        },{
        	id:"pri",
            header: "优先级",
            dataIndex: "pri",
            width: 80,
            editor: new Ext.form.NumberField({
                allowBlank: false,
                validator:function (val){
            		if(val=="")return false;
            		
            		if(val>=1)return true;
            		else return false;
                }
            })
        },
		{
			xtype:"actioncolumn",
			header: "预览",
			width:34,
			items:[{
                  icon:"images/shared/icons/fam/information.png",  // Use a URL in the icon config
                  tooltip:"预览",
                  handler: function(grid, rowIndex, colIndex) {

						if(f_store.getAt(rowIndex).data.fodder==''){
							//Ext.Msg.alert("提示","请先选择素材！");
							Ext.Msg.show({
		   						title:"警告",
		   						msg: "请先选择素材!",
		   						buttons: Ext.Msg.OK,
		   						animEl: "elId",
		   						icon:Ext.MessageBox.WARNING
								});

							return;
						}
						if(stenciltype=="1" || stenciltype==1){
							paper_store.load({
								params:{"paper.period_begin":Ext.getCmp("areaform").getComponent("period_begen").getValue().format("Y-m"),"paper.period_end":Ext.getCmp("areaform").getComponent("period_end").getValue().format("Y-m"),"paper.pid":Ext.getCmp("prod_tree").getSelectionModel().getSelectedNode().id},
								callback:function (){
									if(paper_store.data.items.length<1){

										 //Ext.Msg.alert("提示","此产品卡在有效期内没有预印纸！");
										 Ext.Msg.show({
		   									title:"警告",
		   									msg: "此产品卡在有效期内没有预印纸!",
		   									buttons: Ext.Msg.OK,
		   									animEl: "elId",
		   									icon:Ext.MessageBox.WARNING
								});

									}else{
										if (!paperwin) {
						       				paperwin = new Ext.Window({
								                layout:"fit",
								                width:1100,
								                height:500,
								                closeAction:"hide",
								                plain: true,
								                items:[paper],
								                buttons: [{
								                    text:"确认",
								                    handler: function(){
								                	if(!paper.sm.getSelected()){

								                		 //Ext.Msg.alert("提示","请选择预印纸！");
								                		 Ext.Msg.show({
		   													title:"警告",
		   													msg: "请选择预印纸!",
		   													buttons: Ext.Msg.OK,
		   													animEl: "elId",
		   													icon:Ext.MessageBox.WARNING
															});

								                		 return;
								                	}
								                		var rec = f_store.getAt(rowIndex);
														var stencilNo =Ext.getCmp("stencilNo").getValue();//通过ruleno传递模板id
														var areano =Ext.getCmp("area_no").getValue();//通过id传递模板区域
														var areapaper=areano+"|"+Ext.getCmp("paper").getSelectionModel().getSelected().data.pid;
														var url="rule!viewRulePDF.action?ruleParamRes.ruleno="+stencilNo+"&ruleParamRes.fodder="+rec.data.fodder+"&ruleParamRes.pri="+rec.data.pri+"&ruleParamRes.id="+areapaper;
														var name=rec.data.fodder+"_window";
														var winparams="height=650, width=680, top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no";
														window.open (url, name,winparams);
														paperwin.hide();
								                    }
								                },{
								                    text: "关闭",
								                    handler: function(){
								                        paperwin.hide();
								                    }
								                }]
								            });
							       		}
							       		paperwin.show();
							       	}
								}
							});
						}else{
							var rec = f_store.getAt(rowIndex);
							var stencilNo =Ext.getCmp("stencilNo").getValue();//通过ruleno传递模板id
							var areano =Ext.getCmp("area_no").getValue();//通过id传递模板区域
							var areapaper=areano;
							var url="rule!viewRulePDF.action?ruleParamRes.ruleno="+stencilNo+"&ruleParamRes.fodder="+rec.data.fodder+"&ruleParamRes.pri="+rec.data.pri+"&ruleParamRes.id="+areapaper;
							var name=rec.data.fodder+"_window";
							var winparams="height=650, width=680, top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no";
							window.open (url, name,winparams);
						}
												
                  }
              }]
		}]
    });
			
	var clickRowIndex=0;
    var clickCellIndex=0;
	
	var personrule = new Ext.grid.GridPanel({
		id:"personrule",
		title:"个性化规则",  
      	width:270,
        store: f_store,       
        region:"west", 
        cm: cm,
        stripeRows : true,
        iconCls: "icon-grid",
       	listeners : {
			"rowclick": function (grid , rowIndex ,  e) {
				var record = grid.getStore().getAt(rowIndex);
				personrule2.getStore().reload({
					params:{"ruleParamRes.id":record.data.id}
				});
	       	},
        	"celldblclick" : function (  grid ,  rowIndex , columnIndex , e  ) {
	       		var area =Ext.getCmp("area_no").getValue();
	       		if(area==null  || area=="")return;
	       		if(columnIndex==1){
	       			//var type=area_store.getById(area).data.type;
	       			//if(type==1){
	       				clickRowIndex=rowIndex;
	       				clickCellIndex=columnIndex;
	       				fdata.baseParams["fodder.type"] = Ext.getCmp("fodder_type").getValue();
		         			fdata.baseParams["fodder.begin"] =Ext.getCmp("periodBegen").getValue().format("Y-m");
		         			fdata.baseParams["fodder.end"] =Ext.getCmp("periodEnd").getValue().format("Y-m");
		    	         	fdata.load({params :{start:0,limit:limit}});
			      		//fdata.load({params:{"fodder.type":Ext.getCmp("fodder_type").getValue(),"fodder.begin":Ext.getCmp("periodBegen").getValue().format("Y-m"),"fodder.end":Ext.getCmp("periodEnd").getValue().format("Y-m"),start:0,limit:10}});
			       		if (!win) {
			       			win = new Ext.Window({
				                layout:"fit",
				                 width:1100,
							     height:500,
				                closeAction:"hide",
				                plain: true,
				                items:[selectFodder],
				                buttons: [{
				                    text:"确认",
				                    handler: function(){
				                	if(!selectFodder.sm.getSelected()){

							                		 //Ext.Msg.alert("提示","请选择素材！");
							                		 Ext.Msg.show({
		   												title:"警告",
		   												msg: "请选择素材!",
		   												buttons: Ext.Msg.OK,
		   												animEl: "elId",
		   												icon:Ext.MessageBox.WARNING
														});

							                		 return;
							         }
				                		var record = personrule.getStore().getAt(clickRowIndex);
				                		personrule.getStore().remove(record);
				                		var recordfodder = Ext.getCmp("selectFodder").getSelectionModel().getSelected();
				                		record.data.fodder=recordfodder.data.id;
				                		
				                		personrule.getStore().insert(clickRowIndex ,record);
				                        win.hide();
				                    }
				                },{
				                    text: "关闭",
				                    handler: function(){
				                        win.hide();
				                    }
				                }]
				            });
			       		}
			       		win.show(this);
	       		}
	       		
        	}
       	}
       	
    });
	

	function switchSign(val){
		if(val=="0")return "==";
		if(val=="1")return ">";
		if(val=="2")return "<";
		if(val=="3")return ">=";
		if(val=="4")return "<=";
	}
	
	var personrule2 = new Ext.grid.GridPanel({
        store:rule_store,
        id:"personrule2",        
        region:"center", 
        title:"规则条件设置",
 		columnWidth: .66,
        columns: [{dataIndex : "idx",header : "步骤编号", width: 80},
        		  {dataIndex : "type",header : "维度名称", width: 80,editor:fieldcombox,renderer:fieldRenderer},
			      {dataIndex : "opr1",header : "操作符1", width: 80,renderer:oprRenderer,editor:{
			  		xtype:"billCombox",store:ope_store}},              
			      {dataIndex : "value1",header : "数值1", width: 80},
			      {dataIndex : "opr2",header : "操作符2", width: 80 ,renderer:oprRenderer,editor:{
			  		xtype:"billCombox",
					store:ope_store
				}},
			      {dataIndex : "value2",header : "数值2", width: 80},
			      {dataIndex : "cif",header : "逻辑符", width: 80,renderer:ljRenderer,editor:ljcombox}
			     ]
    });
	
	
	//详细显示图片区域
	var images_panel = {id:"view3",
			xtype:"panel",
			title:"个性化区域图片",
			id:"imagePanel",
			store:image_store,
			width:200,
			height:302,		
			buttonAlign:"center",
			bbar:new Ext.Toolbar({
				buttonAlign:"center",
				items:[{
                icon:"images/shared/icons/fam/collapse.gif",  // Use a URL in the icon config
                tooltip:"上一张",
                handler: function() {
                	if(image_store.getCount()==0){
                		Ext.Msg.show({
		   				title:"提示",
		   				msg:"请选择模板!",
		   				buttons:Ext.Msg.OK,
		   				icon: Ext.MessageBox.WARNING 
						});
						return;
                	}
                	if(img_index==0){
                		img_index = image_store.getCount();
                	}
                	img_index -= 1;
					var page_num = (img_index+1)+"/"+image_store.getCount();
                	Ext.getCmp("show_num").setText(page_num);
					var rec = image_store.getAt(img_index);
					var win=Ext.getCmp("imagePanel");
					win.show();
					var html="<a href=javascript:show_img('"+encodeURI(rec.get('path'))+"');>"+
					"<img width="+win.getInnerWidth()+" height="+win.getInnerHeight()+" src='download.action?id="+encodeURI(rec.get('path'))+"'/></a>";
					win.update(html);
                }
            },{id:"show_num",xtype:"tbtext"},{
                icon:"images/shared/icons/fam/expand.gif",  // Use a URL in the icon config
                tooltip:"下一张",
                handler: function() {
	                if(image_store.getCount()==0){
	                		Ext.Msg.show({
			   				title:"提示",
			   				msg:"请选择模板!",
			   				buttons:Ext.Msg.OK,
			   				icon: Ext.MessageBox.WARNING 
							});
							return;
	                	}
					if(img_index==image_store.getCount()-1){
                		img_index = -1;
                	}
                	img_index += 1;
					var page_num = (img_index+1)+"/"+image_store.getCount();
                	Ext.getCmp("show_num").setText(page_num);
					var rec = image_store.getAt(img_index);
					var win=Ext.getCmp("imagePanel");
					win.show();
					var html="<a href=javascript:show_img('"+encodeURI(rec.get('path'))+"');>"+
					"<img width="+win.getInnerWidth()+" height="+win.getInnerHeight()+" src='download.action?id="+encodeURI(rec.get('path'))+"'/></a>";
					win.update(html);
				}
			}]
			})
		};
	
	var p3=new Ext.Panel({
		autoScroll:true,
		layout:"border",
		border : false,
		items:[
			{
			region: "north",
			height:301,
			border : false,
			layout:'column',
			items: [images_panel,p2]
		 },personrule,personrule2],
		buttonAlign : "center",
		buttons : [{
				text : "返回",
				id:"cancelButton",
				xtype:"button",
				handler : function(){
					Ext.getCmp("rule_panel").layout.setActiveItem(0);
				}
			}]
				
	});

	
	var rule_pel = new Ext.Panel( {
		id:"master_panel",
		border : false,		
		layout : "border",
		items:[{
			id:"prod_tree",
			xtype : "billTreePanel",
			dataUrl : "tree!product.action",
			root : new Ext.tree.AsyncTreeNode( {
				id : "root",
				expanded : true
			// 自动展开节点
					}),
			listeners : {
				"click"	: function(node) {
				    if(node.isLeaf()){
				            Ext.getCmp("a").setValue("");//清空查询项
						    Ext.getCmp("b").setValue("");//清空查询项
						    Ext.getCmp("c").setValue("");//清空查询项
						    
				    	    store.baseParams ={};
				    		store.baseParams["ruleMaster.card_id"] = node.id;
				    		store.load({params:{start : 0,limit : limit}});
				    		Ext.getCmp("rule_panel").layout.setActiveItem(0);
							temp_sotre.load({params :{"template.cardid": node.id,"template.state":1}});
							temp_sotre1.load({params :{"template.cardid": node.id,"template.state":1},
									callback:function(){
		             				Ext.getCmp("b").setValue("");
								}});
				    }
				}
			}
		}, {
			region: "center",
			border : false,	
			id:"rule_panel",
			layout:"card",
			activeItem:0,//显示第一个容器
			items: [p1, p3]
		} ]
	});
	
	field_store.load();
	
	var CenterPanel=Ext.getCmp("CenterPanel");
	CenterPanel.removeAll();
	CenterPanel.add(rule_pel);
	CenterPanel.doLayout();
});
	
</script>